package com.avic.modules.record.rest;

import com.avic.modules.record.domain.AlarmInformation;
import com.avic.modules.record.service.AlarmInformationService;
import com.avic.modules.record.service.dto.AlarmInformationQueryCriteria;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangzikang
 * @date 2022-08-14
 */
@Api(tags = "报警管理: 报警信息")
@RestController
@RequestMapping("/api/equipment/alarm")
@AllArgsConstructor
public class AlarmRecordController {

    private final AlarmInformationService alarmInformationService;


    /**
     * 查看设备点位信息
     * @param criteria
     * @return
     */
    @ApiOperation("查看设备点位信息")
    @GetMapping
    public ResponseEntity<Object> getAlarmRecord(AlarmInformationQueryCriteria criteria, Pageable pageable){

        return new ResponseEntity<>(alarmInformationService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
     * 查看设备点位信息
     * @param criteria
     * @return
     */
    @ApiOperation("查看设备点位信息")
    @GetMapping("/see")
    public ResponseEntity<Object> seeAlarmRecord(AlarmInformationQueryCriteria criteria, Pageable pageable){
        List<Integer> objects = new ArrayList<>();
        objects.add(0);// 任务报警
        objects.add(1);// 任务
        criteria.setTypeAll(objects);
        return new ResponseEntity<>(alarmInformationService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
     * 查看报警记录
     * @return
     */
    @ApiOperation("查看设备点位信息")
    @GetMapping("/callThePolice")
    public ResponseEntity<Object> callThePolice(Pageable pageable){
        return new ResponseEntity<>(alarmInformationService.callThePolice(pageable),HttpStatus.OK);
    }


    /**
     * 修改设备点位信息
     * @param alarmInformation
     * @return
     */
    @ApiOperation("修改设备点位信息")
    @PutMapping
    @PreAuthorize("@el.check('admin','alarm:edit')")
    public ResponseEntity<Object> editAlarmRecord(@Validated @RequestBody AlarmInformation alarmInformation){

        alarmInformationService.updateAlarmInformation(alarmInformation);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
